package com.fenghongzhang.kotlin1903.mvp.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.fenghongzhang.kotlin1903.R
import com.fenghongzhang.kotlin1903.model.Data
import com.fenghongzhang.kotlin1903.plus.toast
import kotlinx.android.synthetic.main.rv_food_layout.view.*

class FoodAdapter(val context: Context,val data:MutableList<Data>) : RecyclerView.Adapter<FoodAdapter.ViewHolder>() {

    inner class ViewHolder(itemView: View) :RecyclerView.ViewHolder(itemView){
        var pic:ImageView = itemView.rv_pic
        var title:TextView = itemView.rv_title
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val inflate =
            LayoutInflater.from(parent.context).inflate(R.layout.rv_food_layout, null, false)

        val viewHolder = ViewHolder(inflate)
        viewHolder.pic.setOnClickListener{
            "sf".toast()
        }
        viewHolder.title.setOnClickListener{

        }
        return viewHolder
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val data1 = data[position]
        holder.title.text = data1.title
        Glide.with(context).load(data1.pic).into(holder.pic)
    }

    override fun getItemCount() = data.size
}


